let utils = require('../../utils/utils.js')
const app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        list: [],
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (option) {
        let userInfo = wx.getStorageSync("userInfo");
        console.log("登录token: ", userInfo.token)
        let _this = this;
        wx.request({
            url: 'https://xinai.icu/api/toy/listScene',
            method: 'POST',
            header: {
                'Content-Type': 'application/json',
                'token': userInfo.token,
            },
            data: {
                limit: 20,
                start: 0,
            },
            success(res) {
                _this.setData({
                    list: res.data.data.scenes
                })
            },
            fail(err) {
                console.log(err)
            }
        });
    },

    pay(e) {
        //判断是否登录
        let userInfo = wx.getStorageSync("userInfo");
        if (! userInfo) {
            utils.setCallbackUrl("switchTab");
            wx.navigateTo({
                url: '/pages/login/login',
            })
        }
        let id = e.currentTarget.dataset.id;
        let status = e.currentTarget.dataset.status;
        if(status == 0) {
            wx.navigateTo({
                url: '/pages/index/buy/buy?id=' + id + '&status=' + status,
            });
        } else {
            wx.navigateTo({
                url: '/pages/index/import/import?id=' + id + '&status=' + status,
            });
        }
        
    },

})